<template>
	<div class="register">
		<Logo></Logo>
		<CheckPhone accountPlaceHolder="请输入注册手机号" btnText="注册" :display="step_1" :callback="checkPhone" ref="checkPhone"></CheckPhone>
		<CheckCode btnText="下一步" :display="step_2" :callback="checkCode" :prev="toCheckPhone" ref="checkCode" sendurl="/auth/register/phone/code"></CheckCode>
		<PassWord btnText="注册" :display="step_3" :callback="register" ref="password"></PassWord>
	</div>
</template>
<script>

	import CheckPhone from 'touch/components/auth/checkphone';
	import CheckCode from 'touch/components/auth/checkcode';
	import PassWord from 'touch/components/auth/password';

	import Logo from 'touch/components/logo';

	import Axios from 'touch/config/axios';

	export default {
		components:{
			Logo,
		    CheckPhone,
		    CheckCode,
		    PassWord,
        },
        data (){
	        return{
	            step_1 : 'show',
	            step_2 : 'hide',
	            step_3 : 'hide',
	        }
	    },
	    methods: {
	    	//发送手机验证码组件返回上一步
			toCheckPhone(){
	    		this.step_1 = 'show';
	    		this.step_2 = 'hide';
	    	},
	    	//验证手机号
			checkPhone(form){
				Axios.Auth.Register.PhoneCheck(form)
	            .then(res =>{
                	if(!res) return false;
                	this.step_1 = 'hide';
                	this.$refs['checkCode'].form.phone = this.$refs['checkPhone'].form.phone;
                	this.$refs['checkCode'].form.phonekey = res.data.phonekey;
                	this.step_2 = 'show';
	            })
			},
			//验证手机验证码
			checkCode(form){
				Axios.Auth.Register.CodeCheck(form)
	            .then(res =>{
                	if(!res) return false;
                	this.$refs['password'].form.phone = this.$refs['checkCode'].form.phone;
                	this.$refs['password'].form.phonekey =this.$refs['checkCode'].form.phonekey;
                	this.$refs['password'].form.key =this.$refs['checkCode'].form.key;
                	this.$refs['password'].form.code =this.$refs['checkCode'].form.code;
                	this.step_2 = 'hide';
                	this.step_3 = 'show';
                })
			},
			//注册
			register(form){
				Axios.Auth.Register.Do(form)
	            .then(res =>{
                	if(!res) return false;
                	this.$vux.toast.show({type : 'success', text: res.msg});
                	this.$router.push({ path: '/login' });
	            })
			}
	    },
	}
</script>
<style>
	
</style>